package com.zhiban.project.controller;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import com.opensymphony.util.FileUtils;

import dinamica.GenericTransaction;
import dinamica.Recordset;

public class GetFileData extends GenericTransaction {

	@Override
	public int service(Recordset inputParams) throws Throwable {
		HttpServletRequest request = getRequest();
		String path = request.getRealPath("/template");
		int rc = super.service(inputParams);
		Recordset rs = this.getRecordset("query-record.sql");
		if (rs.next()) {
			String filename = rs.getString("path");
			File oldFile = new File(path, filename);
			String cstr = FileUtils.readFile(oldFile);
			int body1 = cstr.indexOf("<body>");
			int body2 = cstr.indexOf("</body>");
			String cstr1 = cstr.substring(body1 + 6, body2);
			cstr1 = cstr1.replace("<", "&lt;");
			cstr1 = cstr1.replace(">", "&gt;");
			inputParams.setValue("content", cstr1);
		}
		publish("content", inputParams);
		return rc;
	}

}
